package cn.edu.neu.vmmigeval.cloud.policy.impl;

import cn.edu.neu.vmmigeval.cloud.entity.Host;
import cn.edu.neu.vmmigeval.cloud.entity.Vm;
import cn.edu.neu.vmmigeval.cloud.policy.MigratedHostPolicy;

/**
 * The Static Threshold (THR) Broker allocation policy.
 * @author zzh
 *
 */
public class MigratedHostPolicyStaticThreshold extends MigratedHostPolicy {
	
	/** The utilization threshold. */
	private double utilizationThreshold = 0.9;

	/**
	 * Instantiates a new power vm allocation policy migration mad.
	 *
	 * @param utilizationThreshold the utilization threshold
	 */
	public MigratedHostPolicyStaticThreshold(double utilizationThreshold) {
		super();
		setUtilizationThreshold(utilizationThreshold);
	}

	/**
	 * Checks if is host over utilized.
	 * 
	 * @param host the _host
	 * @return true, if is host over utilized
	 */
	@Override
	public boolean isHostOverUtilized(Host host) {
		//addHistoryEntry(host, getUtilizationThreshold());     //cloudsimԭ��
		double totalRequestedMips = 0;
		for (Vm vm : host.getVmList()) {
			//totalRequestedMips += vm.getCurrentRequestedTotalMips();
			totalRequestedMips += vm.getCurrentCpu();
		}
		double utilization = totalRequestedMips / host.getTotalCpu();
		return utilization > getUtilizationThreshold();
	}

	/**
	 * Sets the utilization threshold.
	 * 
	 * @param utilizationThreshold the new utilization threshold
	 */
	protected void setUtilizationThreshold(double utilizationThreshold) {
		this.utilizationThreshold = utilizationThreshold;
	}

	/**
	 * Gets the utilization threshold.
	 * 
	 * @return the utilization threshold
	 */
	protected double getUtilizationThreshold() {
		return utilizationThreshold;
	}

	@Override
	public boolean isHostUnderUtilized(Host host) {
		// TODO Auto-generated method stub
		return false;
	}

}
